home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1997 October: Mac OS SDK / Dev.CD Oct 97 SDK1.toast / Development Kits (Disc 1) / QuickDraw GX / Programming Stuff / Sample Code / General App Samples / QD PICT To GX Picture ƒ / QD PICT To GX Picture.c < prev    next >
Encoding:
Text File  |  1996-03-20  |  5.8 KB  |  221 lines  |  [TEXT/MMCC]

  1. /*
  2.     QD PICT To QD GX Picture.c 
  3.      
  4.     This files demonstrates the use of the QuickDraw to QuickDraw GX translator. The translator
  5.     will convert all QuickDraw objects to their equivalent GX objects, including PicComments. For 
  6.     complete details about the translator, please see the documentation. The translator is used 
  7.     by QD GX printing to convert all "old" QuickDraw objects to their QuickDraw GX equivalents
  8.     during print time for non-QuickDraw GX based applications.
  9.     
  10.     When you want to draw the QuickDraw GX picture, click within the window.
  11.     
  12.     Enjoy, 
  13.     
  14.     ...Luke
  15.     
  16.     >> Pete "Luke" Alexander
  17.     >> Apple Computer, Developer Technical Support
  18.     
  19.     Notes: 
  20.     • This file requires the "graphics shell.c", "ColorLibrary.c", "TransformLibrary.c" to run.
  21.      
  22.     • This file  prints the best in "landscape". 
  23.     
  24.     ©1992 - 1994  Apple Computer, Inc.
  25.     All rights reserved.
  26. */
  27.  
  28. //#define    MacintoshIncludes    // This allows us to call QD's GXDrawPicture with out a conflict with GX
  29.  
  30.  
  31. #include <Types.h>            // defines noErr
  32. #include <Errors.h>
  33. #include <QuickDraw.h>
  34. #include <Fonts.h>
  35. #include <Dialogs.h>
  36. #include <Memory.h>
  37. #include <Events.h>
  38. #include <FixMath.h>
  39. #include <Windows.h>
  40.  
  41. #include <GXEnvironment.h>
  42. #include <GXPrinting.h>
  43. #include "GraphicsLibraries.h"
  44.  
  45. #include "graphics shell.h"
  46.  
  47.  
  48. //
  49. //  Set up the title and size of the window 
  50. //
  51. Str255     gWindowTitle = "\p QuickDraw PICT (click for GX picture) ";
  52. Rect     gWindowQDRect  = {40, 10, 300, 400};
  53.  
  54. //
  55. //  Once the user have "clicked", this tells us to draw the QuickDraw GX version
  56. //    of the converted QuickDraw PICT.
  57. //
  58. Boolean     gClickState = false;
  59.  
  60. //
  61. //    gGraphicsHeapSize sets the size of the graphics gxHeap created by calling the GXNewGraphicsClient routine
  62. //    in main () within graphics shell.c.  You can determine the amount of graphics gxHeap required by using GraphicsBug.
  63. //    With  gGraphicsHeapSize set to 25k, I had 2 free blocks left in the graphics gxHeap. Sounds good to me.
  64. //
  65. long        gGraphicsHeapSize = 25;
  66.  
  67. gxShape     gShape, gWindowRectangle;
  68.  
  69.  
  70.  
  71. /*------ Protoypes local to this file -------------------------------------------------*/
  72.  
  73. PicHandle CreateQDPicture(void);    
  74.  
  75.  
  76. /*------ CreateQDPicture --------------------------------------------------------------*/
  77.  
  78. PicHandle CreateQDPicture()    
  79. {
  80.   PicHandle     myPict;
  81.   Rect              aRect;
  82.   PenState         *aPenStat;
  83.   short            theFontID;
  84.   
  85.   aPenStat = (PenState*) NewPtr(sizeof(PenState));
  86.   GetPenState(aPenStat);
  87.  
  88.   aPenStat->pnSize.v = 2;
  89.   aPenStat->pnSize.h = 1;
  90.  
  91.   //
  92.   //    Create a QuickDraw picture to be converted to a QuickDraw GX picture.
  93.   //
  94.   myPict = OpenPicture(&gWindowQDRect);
  95.     { 
  96.         SetPenState(aPenStat);               // Set the pen size to 1 gxWide x 2 high
  97.         ClipRect(&gWindowQDRect);
  98.     
  99.         GetFNum("\pTimes", &theFontID);
  100.         TextFont(theFontID);
  101.         TextSize (27);
  102.  
  103.           MoveTo(120,80);
  104.            DrawString("\pThis is only a test...");
  105.     
  106.         SetRect(&aRect,50,40,350,250);
  107.         FrameRect(&aRect);
  108.         MoveTo(350,250);
  109.         LineTo(50,40);
  110.     }
  111.   ClosePicture();
  112.  
  113.   DrawPicture(myPict, &gWindowQDRect);
  114.  
  115.   DisposePtr((Ptr)aPenStat);
  116.   
  117.   return myPict;
  118. } // CreateQDPicture
  119.  
  120.  
  121. /*------ DoInitialization ---------------------------------------------------------------------------------*/
  122.  
  123. void DoInitialization(aWindow)
  124. WindowPtr aWindow;
  125. {
  126.     PicHandle     myPict;
  127.     OSErr        anErr;
  128.     Point        patStretchPoint;
  129.     gxRectangle fixedWindowBounds;           /**  bounding box of the window in local coordinates  **/
  130.  
  131.     GXInitPrinting ();    // We need to initialize printing because we are using the translator
  132.  
  133.      InitCommonColors();
  134.     
  135.     //
  136.     //   Get the bounds of the window, and create a gxRectangle that will fill the window
  137.     //
  138.     GXGetShapeBounds(gWindowBoundsShape, 0L, &fixedWindowBounds);
  139.     gWindowRectangle = GXNewRectangle(&fixedWindowBounds); 
  140.     SetShapeCommonColor (gWindowRectangle ,gxWhite);
  141.  
  142.     SetPort (aWindow);
  143.  
  144.     myPict = CreateQDPicture();
  145.     
  146.     patStretchPoint.v = patStretchPoint.h = 1;  // We do not want any stretching to occur
  147.  
  148.     //
  149.     // Create a GX picture to hold the "translated" QuickDraw picture
  150.     //
  151.     gShape = GXNewShape (gxPictureType);
  152.     
  153.     //    
  154.     // Convert the QuickDraw picture - myPict to a GX picture
  155.     //
  156.     GXConvertPICTToShape(myPict, 
  157.                              gxDefaultOptionsTranslation, 
  158.                              &gWindowQDRect, &gWindowQDRect, 
  159.                              patStretchPoint, gShape, 
  160.                              0);
  161.  
  162.     KillPicture(myPict);
  163. }
  164.  
  165.  
  166. /*------ DoDraw ---------------------------------------------------------------------------------------*/
  167.  
  168. void DoDraw(aWindow)
  169. WindowPtr aWindow;
  170. {
  171.     if (gClickState)
  172.       GXDrawShape (gShape);
  173. }
  174.  
  175.  
  176. /*------ DoDispose -------------------------------------------------------------------------------------*/
  177.  
  178. void DoDispose(aWindow)
  179. WindowPtr aWindow;
  180. {
  181.     /**  
  182.         You should always dispose of your GX graphics objects before tossing your window. Why? It's generally good 
  183.         form and this approach guarantees that everything is disposed. If you had not disposed of everything, the
  184.         call to DisposeWindow should dispose of the objects. If you are running the debugging version of the 
  185.         SecretGraphics init with notices set, you will receive a notice that you had not disposed of everything. You
  186.         can turn notices on in this file by setting gDebugging = TRUE (above).
  187.     **/
  188.     GXDisposeShape(gWindowRectangle);  
  189.     GXDisposeShape(gShape);  
  190.     GXDisposeShape(gWindowBoundsShape);  
  191.        DisposeCommonColors();
  192.      GXExitPrinting ();
  193.        DisposeWindow(aWindow);
  194. }
  195.     
  196.  
  197.  
  198. /*------ DoClick ---------------------------------------------------------------------------------------*/
  199.  
  200. void DoClick( orgMouseLoc, theWindow )
  201. gxPoint        orgMouseLoc;
  202. WindowPtr     theWindow;
  203. {
  204.     if (!gClickState) { 
  205.         SetShapeCommonColor ( gWindowBoundsShape, gxWhite );    
  206.         GXDrawShape ( gWindowBoundsShape );
  207.         GXDrawShape ( gShape );
  208.     
  209.         SetWTitle( theWindow, "\p QuickDraw GX Picture" );
  210.         gClickState = true;
  211.     }
  212. }
  213.  
  214.  
  215. /*------ DoIdle ----------------------------------------------------------------------------------------*/
  216.  
  217. void DoIdle(aWindow)
  218. WindowPtr aWindow;
  219. {
  220. }
  221.